package com.itguigu.glimail.search.controller;

import com.itguigu.glimail.search.service.MailService;
import com.itguigu.glimail.search.vo.SearchParam;
import com.itguigu.glimail.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {
    @Autowired
    private MailService mailService;

    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest request) {
        searchParam.set_queryString(request.getQueryString());
        //1根据传递过来的页面的查询参数,去es中检索商品
        SearchResult result = mailService.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }

}
